package com.platinadesign.axa.view
{
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Graphics;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	
	/**
	 * this class do NOT in charge of zooming or manage effect ..just pure page...this is
	 * enough isolated class ..so you dont have to add any event listenner to deal zooming or anything
	 * therefore ..it faster..
	 * @author DuMing
	 *
	 */
	public class Page extends Sprite
	{
		
		private static const WIDTH : Number = 2000;
		
		private static const HEIGHT : Number = 1200;
		
		

		public function get transparentHalf():Boolean
		{
			return _transparentHalf;
		}

		public function get rightSide() : BitmapData
		{
			return _rightSide.clone();
		}
		
		public function get leftSide() : BitmapData
		{
			return _leftSide.clone();
		}
		
		public function get index() : uint
		{
			return _index;
		}
		
		private var _leftSide : BitmapData;
		
		private var _rightSide : BitmapData;
		
		private var _content : DisplayObject;
		
		private var _index : uint;
		private var _transparentHalf:Boolean;
		
		
		public function Page( content : DisplayObject, index : uint ,transparent:Boolean = false)
		{
			_content = content;
			resetContent();
			_index = index;
			_transparentHalf = transparent;			
			this.scrollRect = new Rectangle( 0, 0, WIDTH, HEIGHT );
			
			initChild();
		}
		public function resetContent() : void
		{
			if( _content is MovieClip )
			{
				MovieClip( _content ).gotoAndStop(1);
			}
		}
		public function playContent() : void
		{
			if( _content is MovieClip )
			{
				MovieClip( _content ).gotoAndPlay(2);
			}
		}
		
		private function initChild() : void
		{
			this.addChild( _content );
			createBitmapData();
		}
		public function get currentLeftSide():BitmapData{
			const newLeft:BitmapData = new BitmapData( WIDTH * 0.5, HEIGHT);
			newLeft.draw( this ,null);
			return newLeft;
		}
		public function get currentRightSide():BitmapData{
			const newRight:BitmapData = new BitmapData( WIDTH * 0.5, HEIGHT);
			const m : Matrix = new Matrix();
			m.translate( -WIDTH * 0.5, 0 );
			newRight.draw( this, m );
			return newRight;
		}
		private function createBitmapData() : void
		{
			_leftSide = new BitmapData( WIDTH * 0.5, HEIGHT,false);
			_leftSide.draw( this );
			_rightSide = new BitmapData( WIDTH * 0.5, HEIGHT,false);
			const m : Matrix = new Matrix();
			m.translate( -WIDTH * 0.5, 0 );
			_rightSide.draw( this, m );
		}
	}
}